<%@ page language="java" contentType="text/html; charset=GBK"  pageEncoding="GBK"  %>
<%@ page import="com.icbc.ssic.base.Credentials"%>
<%@ page import="com.icbc.ssic.base.SSICUserInfo"%>
<%@ page import="java.security.PrivateKey"%>
<%@ page import="java.security.PublicKey"%>
<%@ page import="java.net.URLEncoder"%>
<%@ taglib uri="ctp-tag" prefix="ctp" %>
<%
	String locale=(String)request.getParameter("Language");
	String tellerinfomsg001 = null;
		try{
				tellerinfomsg001 = MessageInstance.getSingleton().getMessage("tellerinfomsg001",locale);		
		}catch(Exception e){		
		}
			String tellerinfomsg002 = null;
		try{
				tellerinfomsg002 = MessageInstance.getSingleton().getMessage("tellerinfomsg002",locale);		
		}catch(Exception e){		
		}
			String tellerinfomsg003 = null;
		try{
				tellerinfomsg003 = MessageInstance.getSingleton().getMessage("tellerinfomsg003",locale);		
		}catch(Exception e){		
		}
			String tellerinfomsg004 = null;
		try{
				tellerinfomsg004 = MessageInstance.getSingleton().getMessage("tellerinfomsg004",locale);		
		}catch(Exception e){		
		}
			String tellerinfomsg005 = null;
		try{
				tellerinfomsg005 = MessageInstance.getSingleton().getMessage("tellerinfomsg005",locale);		
		}catch(Exception e){		
		}
			String tellerinfomsg006 = null;
		try{
				tellerinfomsg006 = MessageInstance.getSingleton().getMessage("tellerinfomsg006",locale);		
		}catch(Exception e){		
		}
			String tellerinfomsg007 = null;
		try{
				tellerinfomsg007 = MessageInstance.getSingleton().getMessage("tellerinfomsg007",locale);		
		}catch(Exception e){		
		}
			String tellerinfomsg008 = null;
		try{
				tellerinfomsg008 = MessageInstance.getSingleton().getMessage("tellerinfomsg008",locale);		
		}catch(Exception e){		
		}
	String tellerNo = null;
	String name = null;
	String gender = null;
	String birthday = null;
	String empcardno = null;
	String department = null;
	String certid = null;
	String certtype = null;

//	PublicKey publicKey = (PublicKey)sessionCtx.getValueAt("ssicData.publicKey");
	PublicKey publicKey = SsicManager.getInstance().getPublicKey();

	boolean result = true;
	String StrErrorMsg = null;

	String ssiAuth=request.getParameter("SSIAuth");
	String ssiSign=request.getParameter("SSISign");
	String ssicRetCode = request.getParameter("retcode");
	System.out.println("aaaaaaaaaaaaa"+ssicRetCode);
	switch(Integer.parseInt(ssicRetCode)){
		case 0:
				result = true;
				break;
		case 1:
				result = false;
				StrErrorMsg = tellerinfomsg001;
				break;
		case 2:
				result = false;
				StrErrorMsg = tellerinfomsg002;
				break;
		case 3:
				result = false;
				StrErrorMsg = tellerinfomsg003;
				break;
		case 4:
				result = false;
				StrErrorMsg = tellerinfomsg004;
				break;
		case 5:
				result = false;
				StrErrorMsg = tellerinfomsg005;
				break;
		default:
				result = false;
				StrErrorMsg = tellerinfomsg006;
				break;
	}

	if (StrErrorMsg==null){
		try
		{
            	Credentials cred = new Credentials(ssiAuth, ssiSign);
            	if(cred.isvalidateUtf8(publicKey))
            	{
            		System.out.println("bbbbbbbbbbb");
					SSICUserInfo userinfo=cred.getSSICUserInfo();
					tellerNo=userinfo.getUsername();
					System.out.println("ccccccccccccccc="+tellerNo);
					name=userinfo.getName();
					gender=userinfo.getGender();
					birthday=userinfo.getBirthday();
					empcardno=userinfo.getEmpcardno();
					department=userinfo.getDepartment();
					certid=userinfo.getID(); 
					certtype=userinfo.getIDType();
					result=true;
	    		} 
	    		else
	    		{
					result=false;
					StrErrorMsg = tellerinfomsg007;
				}
		}
		catch(Exception e)
		{
			result=false;
			StrErrorMsg = tellerinfomsg008;
		}
	}
    %>



<%
	if(result)
	{
%>


<%@page import="com.icbc.ctpdemo.uniform_attestation.SsicManager"%>
<%@page import="com.icbc.ctp.util.MessageInstance"%><ctp:form name="form1" method="post" action="user.flowc" flowActionName="userPreAddOp"> 
        <input type="hidden" name="opFlag" value="0">
		<input type="hidden" name="branchId" value="<%=request.getParameter("selBranchId")%>">
    	<input type="hidden" name="branchName" value="<%=request.getParameter("selBranchName")%>">
		<input type="hidden" name="branchLevel" value="<%=request.getParameter("selBranchLevel")%>">
		<input type="hidden" name="dse_sessionId" value="<%=request.getParameter("dse_sessionId")%>">
</ctp:form>
<script language="javaScript">
	form1.submit();
</script>
<%
	}
	else
	{
	StrErrorMsg=tellerinfomsg008+StrErrorMsg;
%>
<ctp:form name="form2" method="post" action="signin.flowc" flowActionName="errorview">  
        <input type="hidden" name="errorMsg" value="<%=StrErrorMsg%>">
</ctp:form>
<script language="javascript">	
	document.form2.submit();
</script>
<%}%>

